﻿Imports System.Data.Objects
Imports System.Data.Objects.DataClasses
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Spreadsheet
Imports System.Text.RegularExpressions
Imports DataModel

Public Class DataView
  Private con As ConferenceListModel.ConferenceListEntities


  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ConferenceDataGridView.EndEdit()
    con.SaveChanges()
  End Sub


  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    con = New ConferenceListModel.ConferenceListEntities()
    ConferenceDataGridView.DataSource = con.Conferences

  End Sub

  Private Sub ConferenceDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ConferenceDataGridView.CellContentClick

  End Sub

  Private Sub ConferenceDataGridView_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ConferenceDataGridView.RowEnter
    If ConferenceDataGridView.Rows(e.RowIndex).DataBoundItem Is Nothing Then Return

    Dim x = DirectCast(ConferenceDataGridView.Rows(e.RowIndex).DataBoundItem, ConferenceListModel.Conference)
    DataGridView1.DataSource = x.Sessions

  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim pdc09q = From c In con.Conferences
    Where c.ConferenceName = "PDC09"
    Select c

    Dim pdc09 As New MSConferenceImporterPDC09.Import
    pdc09.ImportSessions(CType(pdc09q.First, ConferenceListModel.Conference), True)
    con.SaveChanges()


    Dim mix = From c In con.Conferences
          Where c.ConferenceName = "MIX09"
          Select c

    Dim mix09 As New MSConferenceImporterMIX09.Import
    mix09.ImportSessions(CType(mix.First, ConferenceListModel.Conference), True)
    con.SaveChanges()


    Dim pdc08q = From c In con.Conferences
    Where c.ConferenceName = "PDC08"
    Select c

    Dim pdc08 As New MSConferenceImporterPDC08.Import
    pdc08.ImportSessions(CType(pdc08q.First, ConferenceListModel.Conference), True)
    con.SaveChanges()

    MsgBox("Done Importing")

  End Sub
End Class
